//
// Game.h
//

#pragma once

#include "StepTimer.h"

// A basic game implementation that creates a D3D11 device and
// provides a game loop.
class Game {
public:

	Game() noexcept;
	~Game() = default;

	Game(Game&&) = default;
	Game& operator= (Game&&) = default;

	Game(Game const&) = delete;
	Game& operator= (Game const&) = delete;

	// Initialization and management
	void Initialize(HWND window, int width, int height);

	// Basic game loop
	void Tick();

	// Messages
	void OnActivated();
	void OnDeactivated();
	void OnSuspending();
	void OnResuming();
	void OnWindowSizeChanged(int width, int height);

	// Properties
	void GetDefaultSize(int& width, int& height) const noexcept;

private:

	void Update(DX::StepTimer const& timer);
	void Render();

	void Clear();
	void Present();

	void CreateDevice();
	void CreateResources();

	void OnDeviceLost();

public:
	// Device resources.
	HWND                                            m_window;
	int                                             m_outputWidth;
	int                                             m_outputHeight;

	D3D_FEATURE_LEVEL                               m_featureLevel;
	Microsoft::WRL::ComPtr<ID3D11Device1>           m_d3dDevice;
	Microsoft::WRL::ComPtr<ID3D11DeviceContext1>    m_d3dContext;

	Microsoft::WRL::ComPtr<IDXGISwapChain1>         m_swapChain;
	Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  m_renderTargetView;
	Microsoft::WRL::ComPtr<ID3D11DepthStencilView>  m_depthStencilView;

	Microsoft::WRL::ComPtr<ID3D11BlendState>		m_blendState;

	// Rendering loop timer.
	DX::StepTimer                                   m_timer;

	bool                                            m_fullScreen;

	std::unique_ptr<DirectX::Keyboard>              m_keyboard;
	DirectX::Keyboard::KeyboardStateTracker         m_keyboardTracker;
	std::unique_ptr<DirectX::Mouse>                 m_mouse;
	DirectX::Mouse::ButtonStateTracker              m_mouseTracker;

	float x = 0, y = 0, z = 0;

	int64_t counter = 0;
};
